home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-28 | 1.8 KB | 62 lines | [TEXT/CWIE] |
- // RedBlackKeyTree.h
-
- #ifndef RedBlackKeyTree_h
- #define RedBlackKeyTree_h
-
- #ifndef RedBlackTree_h
- #include "RedBlackTree.h"
- #endif
-
- template < class KeyType > class RedBlackKey;
-
- template < class Key >
- class RedBlackKeyTree: private RedBlackTree
- {
- friend class RedBlackKey< Key >;
-
- typedef RedBlackKey< Key > Node;
- typedef RedBlackNode NodeBase;
- typedef RedBlackTree TreeBase;
-
- private:
- static Node *DownCast( NodeBase *n );
- static const Node *DownCast( const NodeBase *n );
-
- Node *FindTopmost( const Key& k ) const;
- Node *FindFirst( const Key& k ) const;
- Node *FindLast( const Key& k ) const;
- Node& Lookup( const Key& ) const; // Throws ElementNotFound if it's not found
-
- public:
- void Add( Node& );
- void Remove( Node& node ) { TreeBase::Remove( node ); }
-
- TreeBase::RemoveAll;
- TreeBase::IsEmpty;
-
- Node *Root() { return DownCast( TreeBase::Root() ); }
- const Node *Root() const { return DownCast( TreeBase::Root() ); }
-
- Node *First() { return DownCast( TreeBase::First() ); }
- const Node *First() const { return DownCast( TreeBase::First() ); }
-
- Node *Last() { return DownCast( TreeBase::Last() ); }
- const Node *Last() const { return DownCast( TreeBase::Last() ); }
-
- Node *First( const Key& k ) { return FindFirst( k ); }
- const Node *First( const Key& k ) const { return FindFirst( k ); }
-
- Node *Last( const Key& k ) { return FindLast( k ); }
- const Node *Last( const Key& k ) const { return FindLast( k ); }
-
- Node *Find( const Key& k ) { return FindTopmost( k ); }
- const Node *Find( const Key& k ) const { return FindTopmost( k ); }
-
- Node& operator[]( const Key& k ) { return Lookup( k ); }
- const Node& operator[]( const Key& k ) const { return Lookup( k ); }
-
- bool Valid() const;
- };
-
- #endif
-